Dim ActiveCmd
ActiveCmd = "C"

Dim Shell, fullPath, regValue,valueType  
Set Shell = CreateObject("WScript.Shell")

fullPath = "HKEY_CURRENT_USER\Software\MyApp"	
valueName="PADS_SHORTCUTS_ROOT"
Dim root
root = Shell.RegRead(fullPath & "\" & valueName)


If root ="" Then 
	MsgBox "please set env value (PADS_SHORTCUTS_ROOT = ?)"
ELSE	
	Dim folderPath, fileNamePattern, fso, folder, file, found, matches
	folderPath = root & "\skill\B"
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set folder = fso.GetFolder(folderPath)

	fullPath = "HKEY_CURRENT_USER\Software\MyApp"	
	valueName="PADS_Command"
	valueType = "REG_SZ"

	Dim cmdparam 
	cmdparam = Shell.RegRead(fullPath & "\" & valueName)
	cmdparam = cmdparam & ActiveCmd
	cmdparam = LCase(cmdparam)

	fileNamePattern = cmdparam & ".mcr"
	For Each file In folder.Files
		If LCase(file.Name) = LCase(fileNamePattern) Then
			Application.RunMacro(file.path,"")
			Shell.RegWrite fullPath & "\PreCmd", cmdparam, valueType
			cmdparam =""
			Exit For
		End If
	Next

	If Len(cmdparam)>2 Then cmdparam=ActiveCmd
	Shell.RegWrite fullPath & "\", "", "REG_SZ"
	Shell.RegWrite fullPath & "\" & valueName, cmdparam, valueType

End If
